package thread2;

import java.util.Scanner;

public class Demo3 {
//    public volatile static int isQuit = 0;
//
//    public static void main(String[] args) {
//        Thread t1 = new Thread(() -> {
//            while(isQuit == 0){
//                System.out.println("线程 t1 进行");
//            }
//            System.out.println("线程 t1 退出");
//        });
//        t1.start();
//
//        Thread t2 = new Thread(() -> {
//            System.out.println("输入 isQuit：");
//            Scanner in = new Scanner(System.in);
//            isQuit = in.nextInt();
//        });
//        t2.start();
//    }

    public static int isQuit = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while(isQuit == 0){
                System.out.println("线程 t1 进行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程 t1 退出");
        });
        t1.start();

        Thread t2 = new Thread(() -> {
            System.out.println("输入 isQuit：");
            Scanner in = new Scanner(System.in);
            isQuit = in.nextInt();
        });
        t2.start();
    }
}
